import java.util.Scanner;

/**
 * @author: gao
 * @create-date: 2025/3/24 10:31
 */

public class Solution {
    public int minOperations(int[] nums, int x){
        int len = nums.length,sum = 0;
        for (int num : nums) {
            sum += num;
        }
        int target = sum - x;
        if (target < 0) return -1;
        int ret = -1;
        for(int left = 0,right = 0,tmp = 0;right < len;right++){
            tmp += nums[right];
            while(tmp > target){
                tmp -= nums[left++];
            }
            if(tmp == target){
                ret = Math.max(ret,right - left + 1);
            }
        }
        if(ret == -1) return -1;
        else return len - ret;
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while(in.hasNextInt()){
            int len = in.nextInt();
            int[] nums = new int[len];
            for (int i = 0; i < len; i++) {
                nums[i] = in.nextInt();
            }
            int x = in.nextInt();
            Solution solution = new Solution();
            System.out.println(solution.minOperations(nums, x));
        }
    }
}
